<?php
/*
 * 发布管理用
 */
class Libs_Cms_Create{
    protected static $appData = false;
    protected static $appCfg = false;
    protected static $classData = array();

    protected static $tblTitleName = 'cms_document_title_';
    protected static $tblContentName = 'cms_document_content_';
    
    protected static $_cache;
    protected static $_dbAdmin;

    public static function loadDb() {
        self::$_dbAdmin = Db_Admin::instance();
    }
    public static function loadCacheObj(){
		self::$_cache = ME_DAL_RefreshCacheLoader::getInstance();
    }
    
    public static function publishClass($paramArr){
       if (is_array($paramArr)) {
			$options = array(
				'output' => false,
				'appId' => 0,
				'classId' => 0,
				'page' => 1,
			);
			$options = array_merge($options, $paramArr);
			extract($options);
		}
        $appId   = (int)$appId;
        $classId = (int)$classId;
        if(!$output || !$appId || !$classId)return false;
        $page = max(1,$page);

        self::loadDb();
        self::loadCacheObj();
        if(empty(self::$appData)){
            self::$appData = self::$_cache->loadCacheObject("Global_App",array());
        }
        $appInfo = self::$appData;
        //获得APP的配置信息
        if(empty(self::$appCfg)){
            self::$appCfg = ME_Config::get('APP','CONFIG');
        }
        $appCfg = self::$appCfg[$appId];

        //频道信息
        if(!isset(self::$classData[$appId])){
            self::$classData =  self::$_cache->loadCacheObject("Cms_Class",array('appId'=>$appId));
        }
        $output->classInfo =
        $classInfo = self::$classData[$classId];
        //获得所有记录
        $param = array(
                'db'          => self::$_dbAdmin,
                'fromSql'    => "from ".self::$tblTitleName . $appId , #from部分的语句
                'whereSql'   => "where classId = {$classId} and status = 3 ",
                'orderBySql'  => ' order by datetm desc ',
                'pagesize'  => 200,
                'page'      => $page,
               // 'urlTpl'    => 'index.php?c='.$input->ctlName.'&appId='.$input->appId.'&page={PAGE}',
        );
        $listData = Libs_DBHelper::getList($param);
        $output->pageBar = $listData['pageBar'];
        $output->DataList = $listData['list'];


        $output->appInfo =
        $appInfo = $appInfo[$appId];
        $appPath = $appInfo['enName'];
        $classPath = $classInfo['path'];

        //是否开放wap站点
        if($appCfg['hasWap']){
            $tpl = "Template/{$appId}/CmsWap/List";
            $output->setTemplate($tpl);
            $html = $output->fetch();
            $path = PRODUCTION_ROOT . "/Html/".$appCfg['wapPath']."/{$classPath}/";
            if($page == 1){
                $path .= "index.wml" ;
            }else{
                $path .= "p_{$page}.wml" ;
            }

            ME_File::write($html, $path);
        }

        $tpl = "Template/{$appId}/Cms/List";
        $output->setTemplate($tpl);
        $html = $output->fetch();

        $path = PRODUCTION_ROOT . "/Html/{$appPath}/{$classPath}/";
        if($page == 1){
            $path .= "index.shtml" ;
        }else{
            $path .= "p_{$page}.shtml" ;
        }
        ME_File::write($html, $path);

        $url = 'http://' . $appCfg['webUrl'] . "/{$classPath}/";
        return array(
            'url'  => $url,
            'name' => $classInfo['name'],
        );
        
    }

}

?>
